<template>
  <xh-pages>
    <view class="pages-container">
      <view class="item">
        <up-input placeholder="请输入" v-model="formData.value"></up-input>
      </view>
      <view class="item">
        <button class="w-button" @tap="hanldSubmit">提交保存</button>
      </view>
    </view>
  </xh-pages>
</template>
  
<script setup lang="ts">
import { message } from "@/utils/helpers";
import { onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";

const formData = ref({
  field: "",
  value: "",
});
const hanldSubmit = () => {
  uni.$u.http.post("User/userSave", formData.value).then((res: any) => {
    if ([0, 404].includes(res?.code)) {
      message(res?.msg);
      return;
    }
    uni.$emit("hanldUserInfo");
    message("保存成功");
    setTimeout(() => {
      uni.navigateBack();
    }, 1500);
  });
};

onLoad((e: any) => {
  formData.value.field = e?.field || "";
});
</script>
  
<style scoped lang="scss">
.pages-container {
  margin: 30rpx;
  background: #fff;
  padding: 30rpx;

  .item {
    margin-bottom: 40rpx;
  }
}
</style>
  